package org.tamal.classinfo;

import java.io.DataInputStream;
import java.io.IOException;

/**
 * This Class represents LineNumber of LineNumberTable attribute.
 * @author Tamal Kanti Nath
 */
public final class LineNumber {

    private final int start;
    private final int lineNumber;

    private LineNumber(DataInputStream in) throws IOException {
        start = in.readUnsignedShort();
        lineNumber = in.readUnsignedShort();
    }

    /**
     * Returns start_pc.
     * @return the start
     */
    public int getStart() {
        return start;
    }

    /**
     * Returns lineNumber.
     * @return the lineNumber
     */
    public int getLineNumber() {
        return lineNumber;
    }

    @Override
    public String toString() {
        return  lineNumber + ": " + start;
    }

    /**
     * Reads Line Number Table from DataInputStream.
     * @param in the DataInputStream
     * @return the array of InnerClass
     * @throws IOException exception
     * @see Attribute
     */
    static LineNumber[] readLineNumberTable(DataInputStream in)
        throws IOException {
        LineNumber[] table = new LineNumber[in.readUnsignedShort()];
        for (int i = 0; i < table.length; ++i) {
            table[i] = new LineNumber(in);
        }
        return table;
    }
}
